home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / swagg-m / hardware.swg / 0018_CMOS Data.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  8KB  |  264 lines

  1. {
  2. » Does anyone know how to get the hard drive type(s) from CMOS ?
  3. » I can't seem to find this information documented anywhere.
  4.  
  5. This is probably a lot more than you are asking for but. . .
  6. NOTE: one function (Long2Str) is not defined in this because it comes from
  7. a commercial unit.  Basically all it does is convert a number to a string
  8. and return the string.
  9.      This code comes from a unit I wrote to get all kinds of niffty
  10. information about your system.  I think I included everything you will need
  11. to get it up and running.  If you get any strange problems or ones you
  12. can't seem to resolve, let me know and I'll see if I can pass you the right
  13. information.
  14. }
  15.  
  16. Uses
  17.   KMath,
  18.   Dos;
  19.  
  20. type
  21.   String80 = String[80];  { some general purpose string types }
  22.   String40 = String[40];
  23.   String30 = String[30];
  24.   String20 = String[20];
  25.   String12 = String[12];
  26.   String10 = String[10];
  27.   String5  = String[5];
  28.  
  29.   CMOSRec = Record
  30.     Found     : Boolean;  { was a CMOS found to exist }
  31.     CmosDate  : String30; { the date found in CMOS }
  32.     CmosTime  : String30; { the time found in CMOS }
  33.     VideoType : String10; { Type of video found in CMOS }
  34.     Coproc    : Boolean;  { does CMOS report a math coprocessor }
  35.     FloppyA   : String12; { type of floppy drive for A }
  36.     FloppyB   : String12; { Type of floppy drive for B }
  37.     Hard0     : Byte;     { Type of hard drive for drive 0 }
  38.     Hard1     : Byte;     { Type of hard drive for Drive 1 }
  39.     ConvenRam : Word;     { amount of conventional ram indicated }
  40.     ExtendRam : Word;     { amount of extended Ram indicated }
  41.     checkSum  : Boolean;  { Did checksum pass }
  42.   end; { CMOS Rec }
  43.  
  44. const
  45.   { values of constants for CMOS }
  46.   DayName: array[0..7] of string[9] = ('Sunday', 'Monday', 'Tuesday',
  47.                                        'Wednesday', 'Thursday', 'Friday',
  48.                                        'Saturday', 'Sunday');
  49.   MonthName: array[0..12] of string[9] = ('???', 'January', 'February', 'March',
  50.                                           'April', 'May', 'June', 'July',
  51.                                           'August', 'September', 'October',
  52.                                           'November', 'December');
  53.   ScreenName: array[0..3] of string[10] = ('EGA/VGA', 'CGA 40col',
  54.                                            'CGA 80col', 'Monochrome');
  55.   FloppyName: array[0..5] of string[11] = ('none', '5.25" 360K',
  56.                                            '5.25" 1.2M', '3.5"  720K',
  57.                                            '3.5"  1.44M', '3.5"  2.88M');
  58.   CMOSport : Byte = $70; { port to access the CMOS }
  59.  
  60. {===========================================================================}
  61.  
  62.  
  63. VAR
  64.   Regs : Registers; { General purpose variable to access registers }
  65.   CMOS : CMOSRec;   { variable to hold CMOS data }
  66.  
  67. function nocarry : boolean;
  68. { returns the status of the carry flag }
  69. begin
  70.   nocarry:=regs.flags and fcarry = $0000
  71. end; {nocarry}
  72.  
  73. {---------------------------------------------------------------------------}
  74.  
  75. Function ByteToWord(ByteA, ByteB : byte) : word;
  76. begin
  77.    ByteToWord := Word(ByteB) shl 8 + ByteA
  78. end; {cbw}
  79.  
  80. {---------------------------------------------------------------------------}
  81.  
  82. Function BitIsSet(CheckWord : Word; AndValue : Word) : Boolean;
  83. { returns true if the bit(s) indicated in AndValue are set in CheckByte }
  84. BEGIN
  85.   BitIsSet := CheckWord AND AndValue = AndValue;
  86. end;
  87.  
  88. {---------------------------------------------------------------------------}
  89.  
  90. Function ReadCMOS(addr: byte): byte;
  91. { read a value from the CMOS }
  92. Begin
  93.   if CMOSport = $70 then
  94.   begin
  95.     inline($FA);
  96.     Port[CMOSport] := addr;
  97.     readCMOS := Port[CMOSport + 1];
  98.     inline($FB)
  99.   end
  100. end; {readCMOS}
  101.  
  102. {---------------------------------------------------------------------------}
  103.  
  104. function addzero(b: byte): string5;
  105. var
  106.   c2: string[2];
  107. begin
  108.   Str(b:0, c2);
  109.   if b < 10 then
  110.     c2:='0' + c2;
  111.   addzero:=c2
  112. end; {addzero}
  113.  
  114. {---------------------------------------------------------------------------}
  115.  
  116. Function ChangeBCD(b: byte): byte;
  117. { change a BCD into a byte structure }
  118. Begin
  119.   ChangeBCD:=(b and $0F) + ((b shr 4) * 10)
  120. end; {ChangeBCD}
  121.  
  122. {---------------------------------------------------------------------------}
  123.  
  124. Function GetCMOSDate : String30;
  125. { gets the date found in the CMOS and returns it in string format }
  126. VAR
  127.   Date,
  128.   Century,
  129.   Year,
  130.   Month : Byte;
  131.   WorkStr : String30;
  132. BEGIN
  133.   WorkStr := '';
  134.   date    := ChangeBCD(readCMOS(7));
  135.   century := ChangeBCD(readCMOS($32));
  136.   year    := ChangeBCD(readCMOS(9));
  137.   month   := ChangeBCD(readCMOS(8));
  138.   WorkStr := DayName[readCMOS(6)]+', ';
  139.   {case country.DateFormat of
  140.     0, 3..255 :}
  141.       WorkStr := WorkStr + Monthname[month]+' '+IntToStr(date)+', '+IntToStr(century)+addzero(year);
  142.  {   1 :
  143.       WorkStr := WorkStr + Long2Str(date)+', '+Monthname[month]+' '+Long2Str(century)+addzero(Year);
  144.     2 :
  145.       WorkStr := WorkStr + Long2Str(century)+addzero(Year)+', '+Monthname[month]+' '+Long2Str(date);
  146.   end; {case}
  147.   GetCMosDate := workStr;
  148. end; { GetCMOSDate }
  149.  
  150. {---------------------------------------------------------------------------}
  151.  
  152. Function GetCmosTime : String30;
  153. { returns the time as found in the CMOS }
  154. VAR
  155.   CH : Char;
  156.   Hour,
  157.   Min,
  158.   Sec  : Byte;
  159.   WorkStr : String30;
  160.   IsPM    : Boolean;
  161. BEGIN
  162.   workStr := '';
  163.   hour := ChangeBCD(readCMOS(4));
  164.   min := ChangeBCD(readCMOS(2));
  165.   sec := ChangeBCD(readCMOS(0));
  166.   IsPm := false;
  167.   case hour of
  168.         0: hour := 12;
  169.         1..11: hour := hour;
  170.         12: IsPM := true;
  171.         13..23: begin
  172.                   IsPM := true;
  173.                   hour := hour - 12
  174.                 end;
  175.   end; {case}
  176.   WorkStr := WorkStr + AddZero(hour)+':'+addzero(min)+':'+addzero(sec);
  177.   if IsPM then
  178.     workStr := WorkStr + ' PM'
  179.   Else
  180.     WorkStr := WorkStr + ' AM';
  181.   GetCMOSTime := WorkStr;
  182. end; { GetCmosTime }
  183.  
  184. {---------------------------------------------------------------------------}
  185.  
  186. Function GetCmosCheckSum : Boolean;
  187. { performs checksum on CMOS and returns true if ok }
  188. VAR
  189.   CheckSum1,
  190.   CheckSum2 : word;
  191.   Count     : Byte;
  192. BEGIN
  193.   checksum1 := 0;
  194.   for count := $10 to $2D do
  195.     Inc(checksum1, readCMOS(count));
  196.   checksum2 := (word(256) * readCMOS($2E)) + readCMOS($2F);
  197.   if checksum1 = checksum2 then
  198.     GetCmosCheckSum := true
  199.   else
  200.     GetCmosCheckSum := false;
  201. end; { GetCmosCheckSum }
  202.  
  203. {---------------------------------------------------------------------------}
  204.  
  205. Procedure GetCMos;
  206. { gets the cmos record if it exist }
  207. VAR
  208.   Floppy : Byte;
  209. BEGIN
  210.   FillChar(CMOS, SizeOf(CMos), 0);
  211.   regs.AH:=$C0;
  212.   Intr($15, regs);
  213.   if nocarry or (Mem[$F000:$FFFE] <= $FC) then
  214.   With CMOS DO
  215.   begin
  216.     Found := true;
  217.     CMOSDate := GetCMOSDate;
  218.     CMOSTime := GetCmosTime;
  219.     VideoType := ScreenName[(readCMOS($14) shr 4) and 3];
  220.     CoProc := BitIsSet(readCMOS($14), 2);
  221.     Floppy := readCMOS($10);
  222.     if (Floppy shr 4) < 5 then
  223.       FloppyA := FloppyName[floppy shr 4]
  224.     else
  225.       FloppyA := 'Unknown '+ Byte2Hex(floppy shr 4);
  226.     if (floppy and $0F) < 5 then
  227.       FloppyB := FloppyName[floppy and $0F]
  228.     else
  229.       FloppyB := 'Unknown '+ Byte2Hex(floppy and $0F);
  230.  
  231.     Hard0 := readCMOS($12);
  232.     Hard0 := Hard0 shr 4;
  233.     Hard1 := ReadCmos($12);
  234.     Hard1 := Hard1 and $0F;
  235.     if Hard0 = $F then
  236.       Hard0 := readCMOS($19)
  237.     Else Hard0 := $FF; { error }
  238.     if Hard1 = $F then
  239.       Hard1 := readCMOS($1A)
  240.     Else Hard1 := $FF;
  241.     ConvenRam := word(256) * readCMOS($16) + readCMOS($15); { value in K }
  242.     ExtendRam := word(256) * readCMOS($18) + readCMOS($17); { value in K }
  243.     CheckSum := GetCmosCheckSum;
  244.   end
  245.   else
  246.     CMOS.Found := false;
  247. end;
  248.  
  249. begin
  250.   GetCmos;
  251.   Writeln(CMOS.Found);
  252.   Writeln(CMOS.CmosDate);
  253.   Writeln(CMOS.CmosTime);
  254.   Writeln(CMOS.VideoType);
  255.   Writeln(CMOS.Coproc);
  256.   Writeln(CMOS.FloppyA);
  257.   Writeln(CMOS.FloppyB);
  258.   Writeln(CMOS.Hard0);
  259.   Writeln(CMOS.Hard1);
  260.   Writeln(CMOS.ConvenRam);
  261.   Writeln(CMOS.ExtendRam);
  262.   Writeln(CMOS.checkSum);
  263. end.
  264.